﻿using System;

using DreamCube.Framework.DataAccess.Basic;

namespace DreamCube.Websites.TableDesigner
{
    public class DesignerTable : DBObject
    {
        #region "字段"

        private Int32? id = null;
        private String name;
        private Int32 orderIndex;
        private String pageUrl;
        private String html;

        #endregion

        #region "属性"

        /// <summary>
        /// 数据库实例
        /// </summary>
        public override Database DB
        {
            get
            {
                return DBManager.GetDBByConnectionString(DBConnectionStringMgr.GetConnectionStringByAppKey(DBConnectionStrMgr.AppKeyName));
            }
        }

        /// <summary>
        /// 表单的id号
        /// </summary>
        [DBColumn("id", IsPrimaryKey = true, IsIdentity = true)]
        public Int32? ID
        {
            get { return this.id; }
            set { this.id = value; }
        }

        /// <summary>
        /// 表单名称
        /// </summary>
        [DBColumn("name")]
        public String Name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        /// <summary>
        /// 表单序号
        /// </summary>
        [DBColumn("orderindex")]
        public Int32 OrderIndex
        {
            get { return this.orderIndex; }
            set { this.orderIndex = value; }
        }

        /// <summary>
        /// 表单的页面url
        /// </summary>
        [DBColumn("pageurl")]
        public String PageUrl
        {
            get { return this.pageUrl; }
            set { this.pageUrl = value; }
        }

        /// <summary>
        /// 表单的html内容
        /// </summary>
        [DBColumn("html")]
        public String Html
        {
            get { return this.html; }
            set { this.html = value; }
        }

        #endregion

        #region "实例方法"

        public DesignerTable()
            : base("SYS_DesignerTable")
        { }

        #endregion

        #region "静态方法"

        /// <summary>
        /// 创建一个新的表单
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="PageUrl"></param>
        /// <param name="html"></param>
        /// <returns></returns>
        public static Int32 SaveDesignerTable(Int32? id, String name, String pageUrl, String html)
        {
            DesignerTable table = new DesignerTable
            {
                id = id,
                html = html,
                pageUrl = pageUrl,
                name = name
            };
            if (table.SaveToDB())
            {
                return table.id.Value;
            }
            return -1;
        }

        #endregion
    }
}              	
               		
